import { formatDate } from "@/utils";
import * as types from "../actions/actionTypes";

const initOrderData = {
  salePrice: 0,   // 售价
  reducePrice: 0, // 优惠价
  price: 0,       // 实际支付价
  amount: 0,
  stock: 1,
  date: formatDate(new Date()),
  startDate: formatDate(new Date()),
  endDate: formatDate(new Date(), 1),
};

export default function OrderModule(state = initOrderData, action) {
  switch (action.type) {
    // 通过接口，设置显示总价/数量
    case types.SET_PRODUCT_INFO:
      return {
        ...state,
        salePrice: action.salePrice,
        reducePrice: action.reducePrice,
        price: action.price,
        amount: action.amount,
        stock: action.stock != 0 ? 1 : 0,
      };
    // 选中日期，单选
    case types.SET_SELECT_DATE:
      return {
        ...state,
        date: action.date,
      };
    // 酒店开始/结束日期
    case types.SET_SELECT_DATE_RANGE:
      return {
        ...state,
        startDate: action.startDate,
        endDate: action.endDate
      }
    default:
      return state;
  }
}
